﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="ajustarHoras.aspx.cs" Inherits="sistemaAcademicoFinanceiroEscolas.ajustarHoras" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <%
            try
            {
                System.Data.SqlClient.SqlConnection sqlc = new System.Data.SqlClient.SqlConnection(ConfigurationManager.AppSettings["baseDados"]);
                sqlc.Open();
                System.Data.SqlClient.SqlConnection sqld = new System.Data.SqlClient.SqlConnection(ConfigurationManager.AppSettings["baseDados"]);
                sqld.Open();

                System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand("select * from aula", sqlc);
                System.Data.SqlClient.SqlDataReader dr = cmd.ExecuteReader();

                if (dr.HasRows)
                {
                    while (dr.Read())
                    {
                        string horaInicial = dr["horaInicialAula"].ToString();
                        string horaFinal = dr["horaFinalAula"].ToString();
                        string codigoAula = dr["codigoAula"].ToString();

                        if (horaInicial.Length == 4)
                        {
                            horaInicial = "0" + horaInicial;
                        }
                        if (horaFinal.Length == 4)
                        {
                            horaFinal = "0" + horaFinal;
                        }

                        string updateAula = "update aula set horaInicialAula = '" + horaInicial + "', horaFinalAula = '" + horaFinal + "' where codigoAula = " + codigoAula;

                        System.Data.SqlClient.SqlCommand cmdUpdate = new System.Data.SqlClient.SqlCommand(updateAula, sqld);
                        cmdUpdate.ExecuteNonQuery();
                    }
                }

                dr.Close();

                sqlc.Close();
                sqld.Close();
            }
            catch
            {
                Response.Write("Erro!!!");
            }
            finally
            {
                Response.Write("Horas definidas com sucesso!!!");
            }
        %>
    </div>
    </form>
</body>
</html>
